<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
<!--
        <el-button v-if="isAuth('generator:upktradeorder:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('generator:upktradeorder:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="payOrderId"
        header-align="center"
        align="center"
        label="支付流水ID，取值CATEGORY的ID">
      </el-table-column>
      <el-table-column
        prop="tradeSubGoodOrderId"
        header-align="center"
        align="center"
        label="交易子表流水ID，取值TRADE_SUB_ORDER的ID">
      </el-table-column>
      <el-table-column
        prop="tradeGoodsId"
        header-align="center"
        align="center"
        label="交易关联商品快照流水ID，取值TRADE_GOODS的ID">
      </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        label="交易关联用户流水ID，取值USER的ID">
      </el-table-column>
      <el-table-column
        prop="payToolId"
        header-align="center"
        align="center"
        label="用户选择的支付方式的ID,取值表PAY_TOOL表">
      </el-table-column>
      <el-table-column
        prop="consignee"
        header-align="center"
        align="center"
        label="收货人的姓名,用户页面填写,默认取值表USER_ADDRESS">
      </el-table-column>
      <el-table-column
        prop="tel"
        header-align="center"
        align="center"
        label="收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS">
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="收货人的手机,用户页面填写,默认取值表USER_ADDRESS">
      </el-table-column>
      <el-table-column
        prop="bestTime"
        header-align="center"
        align="center"
        label="收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS">
      </el-table-column>
      <el-table-column
        prop="address"
        header-align="center"
        align="center"
        label="收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS">
      </el-table-column>
      <el-table-column
        prop="shippingId"
        header-align="center"
        align="center"
        label="用户选择的配送方式ID,取值表SHIPPING">
      </el-table-column>
      <el-table-column
        prop="shippingTime"
        header-align="center"
        align="center"
        label="订单配送时间">
      </el-table-column>
      <el-table-column
        prop="postscript"
        header-align="center"
        align="center"
        label="订单附言,由用户提交订单前填写">
      </el-table-column>
      <el-table-column
        prop="orderAmount"
        header-align="center"
        align="center"
        label="订单应付款金额即商品总额加配送费加包装费等">
      </el-table-column>
      <el-table-column
        prop="goodsAmount"
        header-align="center"
        align="center"
        label="商品的总金额">
      </el-table-column>
      <el-table-column
        prop="shippingFee"
        header-align="center"
        align="center"
        label="配送费用即外卖系统比较重要">
      </el-table-column>
      <el-table-column
        prop="packFee"
        header-align="center"
        align="center"
        label="包装费用即点餐打包费外卖系统比较重要">
      </el-table-column>
      <el-table-column
        prop="insureFee"
        header-align="center"
        align="center"
        label="保价费用">
      </el-table-column>
      <el-table-column
        prop="payFee"
        header-align="center"
        align="center"
        label="支付手续费用,跟支付方式的配置相关,取值表PAYMENT">
      </el-table-column>
      <el-table-column
        prop="discount"
        header-align="center"
        align="center"
        label="折扣总金额即积分和红包抵扣总额">
      </el-table-column>
      <el-table-column
        prop="integral"
        header-align="center"
        align="center"
        label="消费积分数量，商品可用积分,用户拥有积分中最小者">
      </el-table-column>
      <el-table-column
        prop="integralMoney"
        header-align="center"
        align="center"
        label="使用消费积分金额抵扣的金额">
      </el-table-column>
      <el-table-column
        prop="bonusId"
        header-align="center"
        align="center"
        label="优惠类型，即红包ID, USER_BONUS的BONUS_ID">
      </el-table-column>
      <el-table-column
        prop="bonusMoney"
        header-align="center"
        align="center"
        label="优惠额度，使用红包抵扣的金额">
      </el-table-column>
      <el-table-column
        prop="balanceMoney"
        header-align="center"
        align="center"
        label="使用用户余额抵扣的金额，取用户设定余额,用户可用余额,订单金额中最小者">
      </el-table-column>
      <el-table-column
        prop="moneyPaid"
        header-align="center"
        align="center"
        label="需付款金额即减去优惠总金额后剩余的金额">
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)">
      </el-table-column>
      <el-table-column
        prop="orderScore"
        header-align="center"
        align="center"
        label="订单总评分">
      </el-table-column>
      <el-table-column
        prop="operator"
        header-align="center"
        align="center"
        label="操作员">
      </el-table-column>
      <el-table-column
        prop="createUtc"
        header-align="center"
        align="center"
        label="创建即上传时间">
      </el-table-column>
      <el-table-column
        prop="modifyUtc"
        header-align="center"
        align="center"
        label="修改即更新时间">
      </el-table-column>
      <el-table-column
        prop="isDeleted"
        header-align="center"
        align="center"
        label="是否删除">
      </el-table-column>
      <el-table-column
        prop="version"
        header-align="center"
        align="center"
        label="版本号">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
//  import isInteger from 'lodash/isInteger'  import moment from 'moment'
  import AddOrUpdate from './add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        var params = {
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key
        }
        this.$http({
          url: this.$http.adornUrl('/generator/upktradeorder/list'),
          method: 'get',
          data: this.$http.adornData(params)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/upktradeorder/delete'),
            method: 'post',
            data: ids
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
